<template>
  <div class="street-food">
    <!-- 头部导航 -->
    <div class="header">
      <div class="back-btn" @click="goBack">‹</div>
      <div class="title">影城小吃</div>

    </div>

    <!-- 主要内容区域 -->
    <div class="main-content">
      <!-- 单人餐分类 -->
      <div class="category-section">
        <div class="category-header">
          <h3>单人餐</h3>
        </div>
        
        <div class="snack-list">
          <div 
            v-for="(item,index) in singleMeals" 
            :key="item.id" 
            class="snack-item"
          >
            <div class="snack-image">
              <img :src="item.imgUrl"  alt="暂无图片">
              <div v-if="index==0" class="recommend-tag">推荐最高</div>
            </div>
            <div class="snack-info">
              <div class="snack-name">{{ item.name }}</div>
              <div class="snack-price">
                <span class="current-price">¥ {{ item.currentPrice }}</span>
                <span v-if="item.originalPrice" class="original-price">¥ {{ item.originalPrice }}</span>
              </div>
            </div>
            <div class="purchase-btn" @click="purchaseItem(item)">购买</div>
          </div>
        </div>
      </div>

      <!-- 双人餐分类 -->
      <div class="category-section">
        <div class="category-header">
          <h3>双人餐</h3>
        </div>
        
        <div class="snack-list">
          <div 
            v-for="(item,index) in doubleMeals" 
            :key="item.id" 
            class="snack-item"
          >
            <div class="snack-image">
              <img :src="item.imgUrl" alt="暂无图片">
              <div v-if="index==0" class="recommend-tag">推荐最高</div>
            </div>
            <div class="snack-info">
              <div class="snack-name">{{ item.name }}</div>
              <div class="snack-price">
                <span class="current-price">¥ {{ item.currentPrice }}</span>
                <span v-if="item.originalPrice" class="original-price">¥ {{ item.originalPrice }}</span>
              </div>
            </div>
            <div class="purchase-btn" @click="purchaseItem(item)">购买</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, getCurrentInstance } from 'vue'
import api from '@/utils/http'
const global=getCurrentInstance().appContext.config.globalProperties;

const singleMeals = ref([
])

const doubleMeals = ref([
])

const goBack = () => {
  global.$router.back()
}

// 购买商品
const purchaseItem = (item) => {
  console.log('购买商品:', item.name)
}

onMounted(() => {
  const cinemaId = global.$route.query.cinemaId
  api.get('/streetFood/getList/'+cinemaId).then(res => {
    if(res.data){
      singleMeals.value = res.data["1"]
      doubleMeals.value = res.data["2"]
    }
  })
})
</script>

<style scoped>
.street-food {
  background: #f5f5f5;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  background: white;
  border-bottom: 1px solid #eee;
  position: relative;
}

.back-btn {
  position: absolute;
  left: 16px;
  font-size: 24px;
  color: #333;
  cursor: pointer;
  padding: 4px;
}

.title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.actions {
  position: absolute;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.menu-dots, .location-icon {
  font-size: 18px;
  color: #333;
  cursor: pointer;
  padding: 4px;
}

.main-content {
  padding: 0 0 20px 0;
}

.category-section {
  background: white;
  margin-bottom: 12px;
}

.category-header {
  padding: 16px;
  border-bottom: 1px solid #f0f0f0;
}

.category-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin: 0;
}

.snack-list {
  padding: 0;
}

.snack-item {
  display: flex;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #f8f8f8;
  transition: background-color 0.2s ease;
}

.snack-item:hover {
  background-color: #fafafa;
}

.snack-item:last-child {
  border-bottom: none;
}

.snack-image {
  position: relative;
  flex-shrink: 0;
  margin-right: 12px;
}

.snack-image img {
  width: 70px;
  height: 70px;
  border-radius: 8px;
  object-fit: cover;
}

.recommend-tag {
  position: absolute;
  top: -2px;
  left: -2px;
  background: #ff4757;
  color: white;
  font-size: 8px;
  padding: 2px 4px;
  border-radius: 4px;
  transform: rotate(-15deg);
  font-weight: 600;
}

.snack-info {
  flex: 1;
}

.snack-name {
  font-size: 15px;
  color: #333;
  margin-bottom: 8px;
  font-weight: 500;
}

.snack-price {
  display: flex;
  align-items: center;
  gap: 8px;
}

.current-price {
  font-size: 18px;
  font-weight: 600;
  color: #ff4757;
}

.original-price {
  font-size: 13px;
  color: #999;
  text-decoration: line-through;
}

.purchase-btn {
  background: white;
  color: #ff4757;
  border: 1px solid #ff4757;
  padding: 6px 16px;
  border-radius: 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.purchase-btn:hover {
  background: #ff4757;
  color: white;
}

.purchase-btn:active {
  transform: scale(0.98);
}

@media (max-width: 768px) {
  .snack-image img {
    width: 60px;
    height: 60px;
  }
  
  .snack-name {
    font-size: 14px;
  }
  
  .current-price {
    font-size: 16px;
  }
  
  .purchase-btn {
    padding: 5px 12px;
    font-size: 13px;
  }
}
</style>
